//
//  UIView+Loading.m
//  1gene
//
//  Created by 1jiyin on 16/3/31.
//  Copyright © 2016年 1jiyin. All rights reserved.
//

#import "UIView+Loading.h"
#define TargetID 2000000
@implementation UIView (Loading)
-(void)isLoading:(BOOL)loading
{
    if (loading) {
        UIView *view=[self viewWithTag:TargetID];
        if (view==nil) {
            view=[[UIView alloc]initWithFrame:self.bounds];
            view.tag=TargetID;
            view.backgroundColor=[UIColor grayColor];
            view.alpha=0.7;
            [self addSubview:view];
            
            UIView *view1=[[UIView alloc]init];
            view1.bounds=CGRectMake(0, 0, 100, 50);
            view1.center=view.center;
            view1.backgroundColor=[UIColor blackColor];
            [view addSubview:view1];
            
            UIActivityIndicatorView *indicator=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
            indicator.frame=CGRectMake((100-50)/2.0, 0, 50, 50);
            [indicator startAnimating];
            [view1 addSubview:indicator];
            
            UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame=self.bounds ;
            [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
            [view addSubview:btn];
        }
    }else{
        UIView *view=[self viewWithTag:TargetID];
        [view removeFromSuperview];
    }
}
-(void)btnClick:(UIButton *)sender
{
    UIView *view=[self viewWithTag:TargetID];
    [view removeFromSuperview];
}
@end
